package com.top.mall.jetpack.ma

import com.module.lemlin.http.HttpResponseData
import com.top.mall.app.BaseApplication
import com.top.mall.base.BaseManager
import com.top.mall.entity.*
import rxhttp.RxHttp
import rxhttp.await

class OrderManager : BaseManager() {

    /**
     * waitpay=待支付 waitsend=待发货 waitreceive=待收货 finish = 已完成
     * */
    suspend fun orderIndex(type: String? = null): OrderListResponse {
        val http = RxHttp.get("/api/order/index")
        if (!type.isNullOrEmpty()) {
            http.add("type", type)
        }
        return http.await()
    }

    suspend fun orderDetails(order_id: Int): OrderDetailsResponse =
        RxHttp.get("/api/order/detail")
            .add("order_id", order_id)
            .await()

//    shop_id:15
////address_id:44
//    recipient_id:3
////coupon_id:272
//    delivery_time:1624960800
//    deal_type:0
////user_note:11111111111111111
//    cart_list[]:173
//    cart_list[]:174
//    //cart_list[]:175
////cash_coupon_id[]:6
////cash_coupon_id[]:7
////invoice_id:3
    suspend fun orderSubmit(
        address_id: Int? = null,
        recipient_id: Int? = null,
        delivery_time: Long? = null,
        user_note: String? = null,
        cartList: Array<Int>,
        invoice_id: Int? = null
    ): OrderSubmitResponse {
        val http = RxHttp.get("/api/order/submitOrder")
            .add("shop_id", BaseApplication.SHOP_ID)
            .add("address_id", address_id)
            .add("recipient_id", recipient_id)
            .add("delivery_time", delivery_time)
            .add("deal_type", 0)
        if (!user_note.isNullOrEmpty()) {
            http.add("user_note", user_note)
        }
        for (item in cartList) {
            http.add("cart_list[]", item)
        }
        if (invoice_id != null) {
            http.add("invoice_id", invoice_id)
        }
        return http.await()
    }



    suspend fun orderPayment(order_id: Int): HttpResponseData =
        RxHttp.get("/api/order/payOrder")
            .add("order_id", order_id)
            .add("pay_type","user_money")
            .await()
}